package constraints;

/**
 * Code is heavily inspired from example code in Chapter 8 of
 * Hardcore Java, by Robert Simmons, Jr. Copyright 2001 O'Reilly Media, Inc.,
 * 0-596-00568-7
 *
 * @author Jonathan Caddey
 * 
 */
public class IntConstraint extends Constraint {

	final int my_min_value;
	final int my_max_value;

	public IntConstraint(final String the_name, final int the_min_value,
			final int the_max_value) {
		super(the_name);
		my_min_value = the_min_value;
		my_max_value = the_max_value;
	}
	public int getMinValue() {
		return my_min_value;
	}
	public int getMaxValue() {
		return my_max_value;
	}
	public void validate(final int the_value) {
		if (my_min_value > the_value) {
			throw new ConstraintException(ConstraintException.Type.VALUE_BELOW_MINIMUM);
		}
		if (my_max_value < the_value) {
			throw new ConstraintException(ConstraintException.Type.VALUE_ABOVE_MAXIMUM);
		}
	}
}
